/*
 * VEML6031X00_Application_Library.h
 *
 * Created  : 20 August 2021
 * Modified : 7 June 2021
 * Author   : HWanyusof
 * Version	: 1.2
 */

#include "typedefinition.h"

/*Determine Resolution (in lux/count) From ALS_IT, ALS_GAIN and PD_DIV4
 *VEML6031X00_CAL_Resolution(Byte PD_DIV4, Byte ALS_IT, Byte ALS_GAIN)
 *Byte PD_DIV - Input Parameter:
 *
 * VEML6031X00_PD_DIV4_FULL
 * VEML6031X00_PD_DIV4_QUARTER
 *
 *Byte ALS_IT - Input Parameter:
 *
 * VEML6031X00_ALS_IT_3_125ms
 * VEML6031X00_ALS_IT_6_25ms
 * VEML6031X00_ALS_IT_12_5ms
 * VEML6031X00_ALS_IT_25ms
 * VEML6031X00_ALS_IT_50ms
 * VEML6031X00_ALS_IT_100ms
 * VEML6031X00_ALS_IT_200ms
 * VEML6031X00_ALS_IT_400ms
 *
 *Byte ALS_GAIN - Input Parameter:
 *
 * VEML6031X00_ALS_GAIN_x0_5
 * VEML6031X00_ALS_GAIN_x0_66
 * VEML6031X00_ALS_GAIN_x1
 * VEML6031X00_ALS_GAIN_x2
 *
 *Info: Refer to Table 9 & 10 in Datasheet Page 10
 *
 *returns resolution (lux/count)
 */
float VEML6031X00_CAL_Resolution(Byte PD_DIV4, Byte ALS_IT, Byte ALS_GAIN);

/*Calculate the ALS Lux
 *VEML6031X00_CAL_Lux(float Resolution, float Count)
 *float Resolution - output from VEML6031X00_CAL_Resolution(Byte PD_DIV4, Byte ALS_IT, Byte ALS_GAIN)
 *float Count - output from VEML6031X00_GET_ALS_Data()
 *
 *returns lux
 */
float VEML6031X00_CAL_Lux(float Resolution, float Count);

/*Get Delay for Measurement
 *VEML6031X00_GET_Delay()
 *returns delay in ms
 */
int VEML6031X00_GET_Delay();

//Wait for measurement function
void Wait();

/*Get ALS_IT
 *VEML6031X00_GET_ALS_IT()
 *returns ALS_IT
 */
Byte VEML6031X00_GET_ALS_IT();

/*Get ALS_GAIN
 *VEML6031X00_GET_ALS_GAIN()
 *returns ALS_GAIN
 */
Byte VEML6031X00_GET_ALS_GAIN();

/*Get PD_DIV4
 *VEML6031X00_GET_PD_DIV4()
 *returns PD_DIV4
 */
Byte VEML6031X00_GET_PD_DIV4();

/*Get ALS Mode
 *returns the ALS mode status of the sensor as follows:
 *
 * 0 - ALS Shutdown Mode
 * 1 - AF Mode
 * 2 - Auto Mode
 *
 */
int VEML6031X00_GET_ALS_Mode();

//Reset the Sensor to the default value
void Reset_Sensor();

//Print the output of the sensor
void Print_Data_Only();

//Print the output of the sensor using AGC
void Print_Data_Only_AGC();

/*Print the variable in DEC for debugging
 *Print_Variable_DEC(Word Var)
 *Word Var - Input Parameter:
 *
 * Value between 0d0 and 0d65535
 */
void Print_Variable_DEC(Word Var);

/*Print the variable in HEX for debugging
 *Print_Variable_HEX(Word Var)
 *Word Var - Input Parameter:
 *
 * Value between 0d0 and 0d65535
 */
void Print_Variable_HEX(Word Var);

/*Reverses a string 'str' of length 'len'
 *reverse(char* str, int len)
 *char* str - Array pointer to be reversed
 *int len - Length of the array
 */
void reverse(char* str, int len);

/*Converts a given integer x to string str[].
 *intToStr(int x, char str[], int d)
 *int x - floating-point number to be converted to a string (Both the integer part as well as fraction/decimal point part)
 *char str[] - output string of the floating-point number in the form of array character
 *int d - number of decimal point (the integer part always = 0, the fraction/decimal point part = int afterpoint from ftoa() input)
 */
int intToStr(int x, char str[], int d);

/*Converts a floating-point/double number to string.
 *ftoa(float n, char* res, int afterpoint)
 *float n - floating-point number to be converted to a string
 *char* res - pointer to output string of the floating-point number in the form of array character
 *int d - number of decimal point
 */
void ftoa(float n, char* res, int afterpoint);
